package Thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2023-02-09
 * Time: 21:37
 */
public class Thread18 {
    public static void main(String[] args) throws InterruptedException {
        Object object = new Object();
        Thread t1 = new Thread(()->{
            System.out.println("t1: wait之前");
            synchronized (object){
                try {
                    object.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

            }
            System.out.println("t2: wait之后");
        });
         Thread t2 = new Thread(()->{
             System.out.println("t2: notify之前");
             synchronized (object){
                 try {
                     Thread.sleep(3000);
                 } catch (InterruptedException e) {
                     throw new RuntimeException(e);
                 }
                 object.notify();
             }
             System.out.println("t2: notify之后");

         });
         t1.start();
         Thread.sleep(500);
         t2.start();
    }
}
